package cn.et;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class MailController {
	
	@Autowired
	 JavaMailSender jms;
	
	@GetMapping("/send")
	public String send(String emailto,String emailsubject,String emailcenter){
		
		SimpleMailMessage smm= new SimpleMailMessage();
		//设置发送方
		smm.setFrom("zmw960221@126.com");
		//设置收件方
		smm.setTo(emailto);
		//设置邮件标题
		smm.setSubject(emailsubject);
		//设置邮件内容
		smm.setText(emailcenter);
		jms.send(smm);
		return "1";
	}
	
	@PostMapping("/sends")
	public String sends(@RequestBody Map map){
		
		SimpleMailMessage smm= new SimpleMailMessage();
		//设置发送方
		smm.setFrom("zmw960221@126.com");
		//设置收件方
		smm.setTo(map.get("emailto").toString());
		//设置邮件标题
		smm.setSubject(map.get("emailsubject").toString());
		//设置邮件内容
		smm.setText(map.get("emailcenter").toString());
		jms.send(smm);
		return "1";
	}
}
